﻿<script src="~/Scripts/jquery-easyui-extensions/tree/jeasyui.extensions.tree.getNodes.js"></script>

<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'west',border:false,title:'这里有颗树'" style="width: 200px; border-right-width: 1px;">
        <ul id="tree"></ul>
    </div>
    <div data-options="region:'center',border:false,title:'操作面板'" style="padding:20px;">
        <div style="width:430px;height:350px;border:1px solid red;padding:10px;">
            带层级的数据源格式：
            <pre>
[
    { "id":"1","text":"A",
        "children":
            [
                { "id": "11", "text": "A1" },
                { "id": "12", "text": "A2" },
                { "id": "13", "text": "A3" }
            ] 
    },
    { "id":"2","text":"B" },
    { "id":"3","text":"C" }
]
</pre>
            <br />
            <a id="btnGet1" class="easyui-linkbutton" data-options="iconCls:'icon-add'">获取 west 面板中的 tree 的所有根节点（源生.getRoots）</a>
            <br />
            <br />
            <a id="btnGet2" class="easyui-linkbutton" data-options="iconCls:'icon-add'">获取 west 面板中的 tree 的所有节点（扩展.getNodes）</a>
        </div>
    </div>
</div>

<script>
    $(function () {
        var data = [
            {
                "id": "1", "text": "A",
                "children":
                    [
                        { "id": "11", "text": "A1" },
                        { "id": "12", "text": "A2" },
                        { "id": "13", "text": "A3" }
                    ]
            },
            { "id": "2", "text": "B" },
            { "id": "3", "text": "C" }
        ];

        $("#tree").tree({
            data: data
        });

        $("#btnGet1").click(function () {
            var roots = $("#tree").tree("getRoots");
            alert("执行 tree 源生方法“getRoots”，获取节点数量：" + roots.length);
        });

        $("#btnGet2").click(function () {
            var nodes1 = $("#tree").tree("getNodes");
            alert("执行 tree 扩展方法“getNodes(false)”，获取节点数量：" + nodes1.length);
            var nodes2 = $("#tree").tree("getNodes", true);
            alert("执行 tree 扩展方法“getNodes(true)”，获取节点数量：" + nodes2.length);
        });
    });
</script>